﻿using DeZhen.DataCollection.IRepository.CollectionInstance;
using DeZhen.DataCollection.Model.Entities;
using DeZhen.DataCollection.Model.Enums;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DeZhen.DataCollection.Repository.CollectionInstance
{
    public class CollectionInstanceRepository : BaseRepository<Model.Entities.CollectionInstances>, ICollectionInstanceRepository
    {
        private ISqlSugarClient _db;
        public CollectionInstanceRepository(ISqlSugarClient db) : base(db)
        {
            _db = db;
        }

        public async Task<CollectionInstances> GetLatestInstanceAsync(CollectionTypeEnum collectionType)
        {
            return await _db.Queryable<CollectionInstances>()
                .Where(x => x.CollectionType == collectionType)
                .OrderBy(x => x.CreateTime, OrderByType.Desc)
                .FirstAsync();
        }
    }
}
